home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / fp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  30.0 KB  |  812 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        fp.h
  3.  
  4.      Contains:    FPCE Floating-Point Definitions and Declarations.
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1987-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FP__
  18. #define __FP__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21.     #include <ConditionalMacros.h>
  22. #endif
  23.  
  24. #ifndef __MACTYPES__
  25.     #include <MacTypes.h>
  26. #endif
  27.  
  28.  
  29. /********************************************************************************
  30. *                                                                               *
  31. *    A collection of numerical functions designed to facilitate a wide          *
  32. *    range of numerical programming as required by C9X.                         *
  33. *                                                                               *
  34. *    The <fp.h> declares many functions in support of numerical programming.    *
  35. *    It provides a superset of <math.h> and <SANE.h> functions.  Some           *
  36. *    functionality previously found in <SANE.h> and not in the FPCE <fp.h>      *
  37. *    can be found in this <fp.h> under the heading "__NOEXTENSIONS__".          *
  38. *                                                                               *
  39. *    All of these functions are IEEE 754 aware and treat exceptions, NaNs,      *
  40. *    positive and negative zero and infinity consistent with the floating-      *
  41. *    point standard.                                                            *
  42. *                                                                               *
  43. ********************************************************************************/
  44.  
  45.  
  46.  
  47. #if PRAGMA_ONCE
  48. #pragma once
  49. #endif
  50.  
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54.  
  55. #if PRAGMA_IMPORT
  56. #pragma import on
  57. #endif
  58.  
  59. #if PRAGMA_STRUCT_ALIGN
  60.     #pragma options align=mac68k
  61. #elif PRAGMA_STRUCT_PACKPUSH
  62.     #pragma pack(push, 2)
  63. #elif PRAGMA_STRUCT_PACK
  64.     #pragma pack(2)
  65. #endif
  66.  
  67. /********************************************************************************
  68. *                                                                               *
  69. *                            Efficient types                                    *
  70. *                                                                               *
  71. *    float_t         Most efficient type at least as wide as float              *
  72. *    double_t        Most efficient type at least as wide as double             *
  73. *                                                                               *
  74. *      CPU            float_t(bits)                double_t(bits)               *
  75. *    --------        -----------------            -----------------             *
  76. *    PowerPC          float(32)                    double(64)                   *
  77. *    68K              long double(80/96)           long double(80/96)           *
  78. *    x86              long double(80)              long double(80)              *
  79. *                                                                               *
  80. ********************************************************************************/
  81. #if defined(__MWERKS__) && defined(__cmath__)
  82. /* these types were already defined in MSL's math.h */
  83. #else
  84. #if TARGET_CPU_PPC
  85. typedef float                             float_t;
  86. typedef double                             double_t;
  87. #elif TARGET_CPU_68K
  88. typedef long double                     float_t;
  89. typedef long double                     double_t;
  90. #elif TARGET_CPU_X86
  91. #if NeXT
  92. typedef double                             float_t;
  93. typedef double                             double_t;
  94. #else
  95. typedef long double                     float_t;
  96. typedef long double                     double_t;
  97. #endif  /* NeXT */
  98.  
  99. #elif TARGET_CPU_MIPS
  100. typedef double                             float_t;
  101. typedef double                             double_t;
  102. #elif TARGET_CPU_ALPHA
  103. typedef double                             float_t;
  104. typedef double                             double_t;
  105. #elif TARGET_CPU_SPARC
  106. typedef double                             float_t;
  107. typedef double                             double_t;
  108. #else
  109. #error unsupported CPU
  110. #endif  /*  */
  111.  
  112. /********************************************************************************
  113. *                                                                               *
  114. *                              Define some constants.                           *
  115. *                                                                               *
  116. *    HUGE_VAL            IEEE 754 value of infinity.                            *
  117. *    INFINITY            IEEE 754 value of infinity.                            *
  118. *    NAN                 A generic NaN (Not A Number).                          *
  119. *    DECIMAL_DIG         Satisfies the constraint that the conversion from      *
  120. *                        double to decimal and back is the identity function.   *
  121. *                                                                               *
  122. ********************************************************************************/
  123. #if !TARGET_OS_MAC
  124. #define        NAN                        sqrt(-1)
  125. #else
  126. #define     HUGE_VAL                __inf()
  127. #define     INFINITY                __inf()
  128. #define     NAN                     nan("255")
  129. #endif
  130.  
  131. #if TARGET_CPU_PPC
  132.     #define      DECIMAL_DIG              17 /* does not exist for double-double */
  133. #elif TARGET_CPU_68K
  134.     #define      DECIMAL_DIG              21
  135. #endif      
  136. #endif    /* __MWERKS__ && __cmath__ */
  137. #if TARGET_OS_MAC
  138. /* MSL already defines these */
  139. #if !defined(__MWERKS__) || !defined(__cmath__)
  140. /********************************************************************************
  141. *                                                                               *
  142. *                            Trigonometric functions                            *
  143. *                                                                               *
  144. *   acos        result is in [0,pi].                                            *
  145. *   asin        result is in [-pi/2,pi/2].                                      *
  146. *   atan        result is in [-pi/2,pi/2].                                      *
  147. *   atan2       Computes the arc tangent of y/x in [-pi,pi] using the sign of   *
  148. *               both arguments to determine the quadrant of the computed value. *
  149. *                                                                               *
  150. ********************************************************************************/
  151. EXTERN_API_C( double_t ) cos(double_t x);
  152.  
  153. EXTERN_API_C( double_t ) sin(double_t x);
  154.  
  155. EXTERN_API_C( double_t ) tan(double_t x);
  156.  
  157. EXTERN_API_C( double_t ) acos(double_t x);
  158.  
  159. EXTERN_API_C( double_t ) asin(double_t x);
  160.  
  161. EXTERN_API_C( double_t ) atan(double_t x);
  162.  
  163. EXTERN_API_C( double_t ) atan2(double_t y, double_t x);
  164.  
  165.  
  166.  
  167. /********************************************************************************
  168. *                                                                                *
  169. *                              Hyperbolic functions                             *
  170. *                                                                                *
  171. ********************************************************************************/
  172. EXTERN_API_C( double_t ) cosh(double_t x);
  173.  
  174. EXTERN_API_C( double_t ) sinh(double_t x);
  175.  
  176. EXTERN_API_C( double_t ) tanh(double_t x);
  177.  
  178. EXTERN_API_C( double_t ) acosh(double_t x);
  179.  
  180. EXTERN_API_C( double_t ) asinh(double_t x);
  181.  
  182. EXTERN_API_C( double_t ) atanh(double_t x);
  183.  
  184.  
  185.  
  186. /********************************************************************************
  187. *                                                                                *
  188. *                              Exponential functions                               *
  189. *                                                                                *
  190. *    expm1        expm1(x) = exp(x) - 1.  But, for small enough arguments,          *
  191. *                expm1(x) is expected to be more accurate than exp(x) - 1.        *
  192. *    frexp        Breaks a floating-point number into a normalized fraction       *
  193. *                and an integral power of 2.  It stores the integer in the       *
  194. *                object pointed by *exponent.                                    *
  195. *    ldexp        Multiplies a floating-point    number by an integer power of 2.    *
  196. *    log1p        log1p = log(1 + x). But, for small enough arguments,              *
  197. *                 log1p is expected to be more accurate than log(1 + x).          *
  198. *    logb        Extracts the exponent of its argument, as a signed integral        *
  199. *                  value. A subnormal argument is treated as though it were first    *
  200. *                  normalized. Thus:                                                *
  201. *                                     1   <=   x * 2^(-logb(x))   <   2             *
  202. *    modf        Returns fractional part of x as function result and returns     *
  203. *                integral part of x via iptr. Note C9X uses double not double_t.    *
  204. *    scalb        Computes x * 2^n efficently.  This is not normally done by        *
  205. *                  computing 2^n explicitly.                                         *
  206. *                                                                                *
  207. ********************************************************************************/
  208. EXTERN_API_C( double_t ) exp(double_t x);
  209.  
  210. EXTERN_API_C( double_t ) expm1(double_t x);
  211.  
  212. EXTERN_API_C( double_t ) exp2(double_t x);
  213.  
  214. EXTERN_API_C( double_t ) frexp(double_t x, int *exponent);
  215.  
  216. EXTERN_API_C( double_t ) ldexp(double_t x, int n);
  217.  
  218. EXTERN_API_C( double_t ) log(double_t x);
  219.  
  220. EXTERN_API_C( double_t ) log2(double_t x);
  221.  
  222. EXTERN_API_C( double_t ) log1p(double_t x);
  223.  
  224. EXTERN_API_C( double_t ) log10(double_t x);
  225.  
  226. EXTERN_API_C( double_t ) logb(double_t x);
  227.  
  228. EXTERN_API_C( long double ) modfl(long double x, long double *iptrl);
  229.  
  230. EXTERN_API_C( double_t ) modf(double_t x, double_t *iptr);
  231.  
  232. EXTERN_API_C( float ) modff(float x, float *iptrf);
  233.  
  234.  
  235. EXTERN_API_C( double_t ) scalb(double_t x, long n);
  236.  
  237. /********************************************************************************
  238. *                                                                                *
  239. *                     Power and absolute value functions                          *
  240. *                                                                                *
  241. *    hypot        Computes the square root of the sum of the squares of its        *
  242. *                  arguments, without undue overflow or underflow.                 *
  243. *    pow            Returns x raised to the power of y.  Result is more accurate    *
  244. *                than using exp(log(x)*y).                                        *
  245. *                                                                                *
  246. ********************************************************************************/
  247. EXTERN_API_C( double_t ) fabs(double_t x);
  248.  
  249. EXTERN_API_C( double_t ) hypot(double_t x, double_t y);
  250.  
  251. EXTERN_API_C( double_t ) pow(double_t x, double_t y);
  252.  
  253. EXTERN_API_C( double_t ) sqrt(double_t x);
  254.  
  255.  
  256.  
  257. /********************************************************************************
  258. *                                                                                 *
  259. *                        Gamma and Error functions                               *
  260. *                                                                                 *
  261. *     erf            The error function.                                             *
  262. *     erfc        Complementary error function.                                      *
  263. *     gamma        The gamma function.                                                *
  264. *     lgamma        Computes the base-e logarithm of the absolute value of            *
  265. *                 gamma of its argument x, for x > 0.                                *
  266. *                                                                                 *
  267. ********************************************************************************/
  268. EXTERN_API_C( double_t ) erf(double_t x);
  269.  
  270. EXTERN_API_C( double_t ) erfc(double_t x);
  271.  
  272. EXTERN_API_C( double_t ) gamma(double_t x);
  273.  
  274. EXTERN_API_C( double_t ) lgamma(double_t x);
  275.  
  276.  
  277.  
  278. /********************************************************************************
  279. *                                                                                 *
  280. *                        Nearest integer functions                                 *
  281. *                                                                                 *
  282. *     rint        Rounds its argument to an integral value in floating point         *
  283. *                  format, honoring the current rounding direction.                   *
  284. *                                                                                 *
  285. *     nearbyint    Differs from rint only in that it does not raise the inexact    *
  286. *               exception. It is the nearbyint function recommended by the        *
  287. *                  IEEE floating-point standard 854.                                  *
  288. *                                                                                 *
  289. *     rinttol        Rounds its argument to the nearest long int using the current     *
  290. *                  rounding direction.  NOTE: if the rounded value is outside        *
  291. *                the range of long int, then the result is undefined.              *
  292. *                                                                                  *
  293. *     round        Rounds the argument to the nearest integral value in floating     *
  294. *                  point format similar to the Fortran "anint" function. That is:  *
  295. *                  add half to the magnitude and chop.                             *
  296. *                                                                                 *
  297. *     roundtol    Similar to the Fortran function nint or to the Pascal round.    *
  298. *                 NOTE: if the rounded value is outside the range of long int,    *
  299. *                  then the result is undefined.                                      *
  300. *                                                                                 *
  301. *     trunc        Computes the integral value, in floating format, nearest to        *
  302. *                 but no larger in magnitude than its argument.      NOTE: on 68K    *
  303. *                compilers when using -elems881, trunc must return an int        *
  304. *                                                                                 *
  305. ********************************************************************************/
  306. EXTERN_API_C( double_t ) ceil(double_t x);
  307.  
  308. EXTERN_API_C( double_t ) floor(double_t x);
  309.  
  310. EXTERN_API_C( double_t ) rint(double_t x);
  311.  
  312. EXTERN_API_C( double_t ) nearbyint(double_t x);
  313.  
  314. EXTERN_API_C( long ) rinttol(double_t x);
  315.  
  316. EXTERN_API_C( double_t ) round(double_t x);
  317.  
  318. EXTERN_API_C( long ) roundtol(double_t round);
  319.  
  320. #if TARGET_RT_MAC_68881
  321. EXTERN_API_C( int ) trunc(double_t x);
  322.  
  323. #else
  324. EXTERN_API_C( double_t ) trunc(double_t x);
  325.  
  326. #endif  /* TARGET_RT_MAC_68881 */
  327.  
  328.  
  329. /********************************************************************************
  330. *                                                                                 *
  331. *                            Remainder functions                                   *
  332. *                                                                                 *
  333. *     remainder        IEEE 754 floating point standard for remainder.                *
  334. *     remquo            SANE remainder.  It stores into 'quotient' the 7 low-order    *
  335. *                    bits of the integer quotient x/y, such that:                *
  336. *                        -127 <= quotient <= 127.                                 *
  337. *                                                                                 *
  338. ********************************************************************************/
  339. EXTERN_API_C( double_t ) fmod(double_t x, double_t y);
  340.  
  341. EXTERN_API_C( double_t ) remainder(double_t x, double_t y);
  342.  
  343. EXTERN_API_C( double_t ) remquo(double_t x, double_t y, int *quo);
  344.  
  345.  
  346.  
  347. /********************************************************************************
  348. *                                                                                 *
  349. *                             Auxiliary functions                               *
  350. *                                                                                 *
  351. *     copysign        Produces a value with the magnitude of its first argument    *
  352. *                      and sign of its second argument.  NOTE: the order of the     *
  353. *                      arguments matches the recommendation of the IEEE 754         *
  354. *                    floating point standard,  which is opposite from the SANE    *
  355. *                    copysign function.                                             *
  356. *                                                                                 *
  357. *     nan                The call 'nan("n-char-sequence")' returns a quiet NaN         *
  358. *                      with content indicated through tagp in the selected         *
  359. *                    data type format.                                              *
  360. *                                                                                *
  361. *     nextafter        Computes the next representable value after 'x' in the         *
  362. *                    direction of 'y'.  if x == y, then y is returned.            *
  363. *                                                                                 *
  364. ********************************************************************************/
  365. EXTERN_API_C( double_t ) copysign(double_t x, double_t y);
  366.  
  367. EXTERN_API_C( long double ) nanl(const char *tagp);
  368.  
  369. EXTERN_API_C( double ) nan(const char *tagp);
  370.  
  371. EXTERN_API_C( float ) nanf(const char *tagp);
  372.  
  373. EXTERN_API_C( long double ) nextafterl(long double x, long double y);
  374.  
  375. EXTERN_API_C( double ) nextafterd(double x, double y);
  376.  
  377. EXTERN_API_C( float ) nextafterf(float x, float y);
  378.  
  379.  
  380.  
  381. /********************************************************************************
  382. *                                                                                 *
  383. *                              Inquiry macros                                   *
  384. *                                                                                 *
  385. *     fpclassify        Returns one of the FP_* values.                                *
  386. *     isnormal        Non-zero if and only if the argument x is normalized.          *
  387. *     isfinite        Non-zero if and only if the argument x is finite.             *
  388. *     isnan            Non-zero if and only if the argument x is a NaN.              *
  389. *     signbit            Non-zero if and only if the sign of the argument x is        *
  390. *                      negative.  This includes, NaNs, infinities and zeros.         *
  391. *                                                                                 *
  392. ********************************************************************************/
  393. enum {
  394.     FP_SNAN                        = 0,                            /*      signaling NaN                         */
  395.     FP_QNAN                        = 1,                            /*      quiet NaN                             */
  396.     FP_INFINITE                    = 2,                            /*      + or - infinity                       */
  397.     FP_ZERO                        = 3,                            /*      + or - zero                           */
  398.     FP_NORMAL                    = 4,                            /*      all normal numbers                    */
  399.     FP_SUBNORMAL                = 5                                /*      denormal numbers                      */
  400. };
  401.  
  402.  
  403.  
  404. #define      fpclassify(x)    ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  405.                               __fpclassify  ( x ) :                            \
  406.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  407.                               __fpclassifyd ( x ) :                            \
  408.                               __fpclassifyf ( x ) )
  409. #define      isnormal(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  410.                               __isnormal ( x ) :                               \
  411.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  412.                               __isnormald ( x ) :                              \
  413.                               __isnormalf ( x ) )
  414. #define      isfinite(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  415.                               __isfinite ( x ) :                               \
  416.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  417.                               __isfinited ( x ) :                              \
  418.                               __isfinitef ( x ) )
  419. #define      isnan(x)         ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  420.                               __isnan ( x ) :                                  \
  421.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  422.                               __isnand ( x ) :                                 \
  423.                               __isnanf ( x ) )
  424. #define      signbit(x)       ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  425.                               __signbit ( x ) :                                \
  426.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  427.                               __signbitd ( x ) :                               \
  428.                               __signbitf ( x ) )
  429.  
  430.  
  431. EXTERN_API_C( long ) __fpclassify(long double x);
  432.  
  433. EXTERN_API_C( long ) __fpclassifyd(double x);
  434.  
  435. EXTERN_API_C( long ) __fpclassifyf(float x);
  436.  
  437. EXTERN_API_C( long ) __isnormal(long double x);
  438.  
  439. EXTERN_API_C( long ) __isnormald(double x);
  440.  
  441. EXTERN_API_C( long ) __isnormalf(float x);
  442.  
  443. EXTERN_API_C( long ) __isfinite(long double x);
  444.  
  445. EXTERN_API_C( long ) __isfinited(double x);
  446.  
  447. EXTERN_API_C( long ) __isfinitef(float x);
  448.  
  449. EXTERN_API_C( long ) __isnan(long double x);
  450.  
  451. EXTERN_API_C( long ) __isnand(double x);
  452.  
  453. EXTERN_API_C( long ) __isnanf(float x);
  454.  
  455. EXTERN_API_C( long ) __signbit(long double x);
  456.  
  457. EXTERN_API_C( long ) __signbitd(double x);
  458.  
  459. EXTERN_API_C( long ) __signbitf(float x);
  460.  
  461. EXTERN_API_C( double_t ) __inf(void );
  462.  
  463.  
  464.  
  465. /********************************************************************************
  466. *                                                                                 *
  467. *                      Max, Min and Positive Difference                         *
  468. *                                                                                 *
  469. *     fdim        Determines the 'positive difference' between its arguments:     *
  470. *                { x - y, if x > y }, { +0, if x <= y }.  If one argument is        *
  471. *                  NaN, then fdim returns that NaN.  if both arguments are NaNs,     *
  472. *                 then fdim returns the first argument.                            *
  473. *                                                                                 *
  474. *     fmax        Returns the maximum of the two arguments.  Corresponds to the    *
  475. *                max function in FORTRAN.  NaN arguments are treated as missing     *
  476. *                data.  If one argument is NaN and the other is a number, then     *
  477. *                the number is returned.  If both are NaNs then the first         *
  478. *                argument is returned.                                             *
  479. *                                                                                 *
  480. *     fmin        Returns the minimum of the two arguments.  Corresponds to the    *
  481. *                min function in FORTRAN.  NaN arguments are treated as missing     *
  482. *                data.  If one argument is NaN and the other is a number, then     *
  483. *                the number is returned.  If both are NaNs then the first         *
  484. *                argument is returned.                                            *
  485. *                                                                                 *
  486. ********************************************************************************/
  487. EXTERN_API_C( double_t ) fdim(double_t x, double_t y);
  488.  
  489. EXTERN_API_C( double_t ) fmax(double_t x, double_t y);
  490.  
  491. EXTERN_API_C( double_t ) fmin(double_t x, double_t y);
  492.  
  493. #endif /* !defined(__MWERKS__) || !defined(__cmath__) */
  494.  
  495. /*******************************************************************************
  496. *                                Constants                                     *
  497. *******************************************************************************/
  498. extern const double_t pi;
  499. /********************************************************************************
  500. *                                                                                 *
  501. *                              Non NCEG extensions                                *
  502. *                                                                                 *
  503. ********************************************************************************/
  504. #ifndef __NOEXTENSIONS__
  505. /********************************************************************************
  506. *                                                                                 *
  507. *                              Financial functions                              *
  508. *                                                                                 *
  509. *     compound        Computes the compound interest factor "(1 + rate)^periods"    *
  510. *                      more accurately than the straightforward computation with     *
  511. *                    the Power function.  This is SANE's compound function.      *
  512. *                                                                                 *
  513. *     annuity            Computes the present value factor for an annuity             *
  514. *                      "(1 - (1 + rate)^(-periods)) /rate" more accurately than    *
  515. *                    the straightforward computation with the Power function.     *
  516. *                    This is SANE's annuity function.                              *
  517. *                                                                                 *
  518. ********************************************************************************/
  519. EXTERN_API_C( double_t ) compound(double_t rate, double_t periods);
  520.  
  521. EXTERN_API_C( double_t ) annuity(double_t rate, double_t periods);
  522.  
  523.  
  524.  
  525. /********************************************************************************
  526. *                                                                                 *
  527. *                              Random function                                  *
  528. *                                                                                 *
  529. *     randomx            A pseudorandom number generator.  It uses the iteration:    *
  530. *                                (7^5*x)mod(2^31-1)                                *
  531. *                                                                                 *
  532. ********************************************************************************/
  533. EXTERN_API_C( double_t ) randomx(double_t *x);
  534.  
  535.  
  536.  
  537. /*******************************************************************************
  538. *                              Relational operator                             *
  539. *******************************************************************************/
  540. /*      relational operator      */
  541. typedef short                             relop;
  542. enum {
  543.     GREATERTHAN                    = 0,
  544.     LESSTHAN                    = 1,
  545.     EQUALTO                        = 2,
  546.     UNORDERED                    = 3
  547. };
  548.  
  549. #if !defined(__MWERKS__) || !defined(__cmath__)
  550. EXTERN_API_C( relop ) relation(double_t x, double_t y);
  551.  
  552. #endif /* !defined(__MWERKS__) || !defined(__cmath__) */
  553.  
  554.  
  555. /********************************************************************************
  556. *                                                                                 *
  557. *                         Binary to decimal conversions                         *
  558. *                                                                                 *
  559. *     SIGDIGLEN    Significant decimal digits.                                        *
  560. *                                                                                 *
  561. *     decimal        A record which provides an intermediate unpacked form for        *
  562. *                programmers who wish to do their own parsing of numeric input     *
  563. *                or formatting of numeric output.                                  *
  564. *                                                                                 *
  565. *     decform        Controls each conversion to a decimal string.  The style field     *
  566. *                is either FLOATDECIMAL or FIXEDDECIMAL. If FLOATDECIMAL, the     *
  567. *                value of the field digits is the number of significant digits.  *
  568. *                  If FIXEDDECIMAL value of the field digits is the number of        *
  569. *                digits to the right of the decimal point.                         *
  570. *                                                                                 *
  571. *     num2dec        Converts a double_t to a decimal record    using a decform.        *
  572. *     dec2num        Converts a decimal record d to a double_t value.                *
  573. *     dec2str        Converts a decform and decimal to a string using a decform.        *
  574. *     str2dec        Converts a string to a decimal struct.                            *
  575. *     dec2d        Similar to dec2num except a double is returned (68k only).        *
  576. *     dec2f        Similar to dec2num except a float is returned.                    *
  577. *     dec2s        Similar to dec2num except a short is returned.                    *
  578. *     dec2l        Similar to dec2num except a long is returned.                     *
  579. *                                                                                 *
  580. ********************************************************************************/
  581. #if    TARGET_CPU_PPC
  582.     #define SIGDIGLEN      36  
  583. #elif TARGET_CPU_68K
  584.     #define SIGDIGLEN      20
  585. #elif TARGET_CPU_X86
  586.     #define SIGDIGLEN      20
  587. #endif
  588. #define      DECSTROUTLEN   80               /* max length for dec2str output */
  589. #define      FLOATDECIMAL   ((char)(0))
  590. #define      FIXEDDECIMAL   ((char)(1))
  591. struct decimal {
  592.     char                             sgn;                        /* sign 0 for +, 1 for - */
  593.     char                             unused;
  594.     short                             exp;                        /* decimal exponent */
  595.     struct {
  596.         unsigned char                     length;
  597.         unsigned char                     text[SIGDIGLEN];        /* significant digits */
  598.         unsigned char                     unused;
  599.     }                                 sig;
  600. };
  601. typedef struct decimal decimal;
  602.  
  603. struct decform {
  604.     char                             style;                        /*  FLOATDECIMAL or FIXEDDECIMAL */
  605.     char                             unused;
  606.     short                             digits;
  607. };
  608. typedef struct decform decform;
  609. EXTERN_API_C( void ) num2dec(const decform *f, double_t x, decimal *d);
  610.  
  611. EXTERN_API_C( double_t ) dec2num(const decimal *d);
  612.  
  613. EXTERN_API_C( void ) dec2str(const decform *f, const decimal *d, char *s);
  614.  
  615. EXTERN_API_C( void ) str2dec(const char *s, short *ix, decimal *d, short *vp);
  616.  
  617. #if TARGET_CPU_68K
  618. EXTERN_API_C( double ) dec2d(const decimal *d);
  619.  
  620. #endif  /* TARGET_CPU_68K */
  621.  
  622. EXTERN_API_C( float ) dec2f(const decimal *d);
  623.  
  624. EXTERN_API_C( short ) dec2s(const decimal *d);
  625.  
  626. EXTERN_API_C( long ) dec2l(const decimal *d);
  627.  
  628.  
  629.  
  630.  
  631. /********************************************************************************
  632. *                                                                                 *
  633. *                         68k-only Transfer Function Prototypes                 *
  634. *                                                                                 *
  635. ********************************************************************************/
  636. #if TARGET_CPU_68K
  637. EXTERN_API_C( void ) x96tox80(const extended96 *x, extended80 *x80);
  638.  
  639. EXTERN_API_C( void ) x80tox96(const extended80 *x80, extended96 *x);
  640.  
  641. #endif  /* TARGET_CPU_68K */
  642.  
  643. #endif  /* !defined(__NOEXTENSIONS__) */
  644.  
  645. /********************************************************************************
  646. *                                                                                 *
  647. *                         PowerPC-only Function Prototypes                         *
  648. *                                                                                 *
  649. ********************************************************************************/
  650.  
  651. #if TARGET_CPU_PPC
  652. #ifndef __MWERKS__    /* Metrowerks does not support double double */
  653. EXTERN_API_C( long double ) cosl(long double x);
  654.  
  655. EXTERN_API_C( long double ) sinl(long double x);
  656.  
  657. EXTERN_API_C( long double ) tanl(long double x);
  658.  
  659. EXTERN_API_C( long double ) acosl(long double x);
  660.  
  661. EXTERN_API_C( long double ) asinl(long double x);
  662.  
  663. EXTERN_API_C( long double ) atanl(long double x);
  664.  
  665. EXTERN_API_C( long double ) atan2l(long double y, long double x);
  666.  
  667. EXTERN_API_C( long double ) coshl(long double x);
  668.  
  669. EXTERN_API_C( long double ) sinhl(long double x);
  670.  
  671. EXTERN_API_C( long double ) tanhl(long double x);
  672.  
  673. EXTERN_API_C( long double ) acoshl(long double x);
  674.  
  675. EXTERN_API_C( long double ) asinhl(long double x);
  676.  
  677. EXTERN_API_C( long double ) atanhl(long double x);
  678.  
  679. EXTERN_API_C( long double ) expl(long double x);
  680.  
  681. EXTERN_API_C( long double ) expm1l(long double x);
  682.  
  683. EXTERN_API_C( long double ) exp2l(long double x);
  684.  
  685. EXTERN_API_C( long double ) frexpl(long double x, int *exponent);
  686.  
  687. EXTERN_API_C( long double ) ldexpl(long double x, int n);
  688.  
  689. EXTERN_API_C( long double ) logl(long double x);
  690.  
  691. EXTERN_API_C( long double ) log1pl(long double x);
  692.  
  693. EXTERN_API_C( long double ) log10l(long double x);
  694.  
  695. EXTERN_API_C( long double ) log2l(long double x);
  696.  
  697. EXTERN_API_C( long double ) logbl(long double x);
  698.  
  699. EXTERN_API_C( long double ) scalbl(long double x, long n);
  700.  
  701. EXTERN_API_C( long double ) fabsl(long double x);
  702.  
  703. EXTERN_API_C( long double ) hypotl(long double x, long double y);
  704.  
  705. EXTERN_API_C( long double ) powl(long double x, long double y);
  706.  
  707. EXTERN_API_C( long double ) sqrtl(long double x);
  708.  
  709. EXTERN_API_C( long double ) erfl(long double x);
  710.  
  711. EXTERN_API_C( long double ) erfcl(long double x);
  712.  
  713. EXTERN_API_C( long double ) gammal(long double x);
  714.  
  715. EXTERN_API_C( long double ) lgammal(long double x);
  716.  
  717. EXTERN_API_C( long double ) ceill(long double x);
  718.  
  719. EXTERN_API_C( long double ) floorl(long double x);
  720.  
  721. EXTERN_API_C( long double ) rintl(long double x);
  722.  
  723. EXTERN_API_C( long double ) nearbyintl(long double x);
  724.  
  725. EXTERN_API_C( long ) rinttoll(long double x);
  726.  
  727. EXTERN_API_C( long double ) roundl(long double x);
  728.  
  729. EXTERN_API_C( long ) roundtoll(long double round);
  730.  
  731. EXTERN_API_C( long double ) truncl(long double x);
  732.  
  733. EXTERN_API_C( long double ) remainderl(long double x, long double y);
  734.  
  735. EXTERN_API_C( long double ) remquol(long double x, long double y, int *quo);
  736.  
  737. EXTERN_API_C( long double ) copysignl(long double x, long double y);
  738.  
  739. EXTERN_API_C( long double ) fdiml(long double x, long double y);
  740.  
  741. EXTERN_API_C( long double ) fmaxl(long double x, long double y);
  742.  
  743. EXTERN_API_C( long double ) fminl(long double x, long double y);
  744.  
  745. #endif /* __MWERKS__ */
  746. #ifndef __NOEXTENSIONS__
  747. EXTERN_API_C( relop ) relationl(long double x, long double y);
  748.  
  749. EXTERN_API_C( void ) num2decl(const decform *f, long double x, decimal *d);
  750.  
  751. EXTERN_API_C( long double ) dec2numl(const decimal *d);
  752.  
  753. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  754.  
  755. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  756.  
  757. /*    
  758.             MathLib v2 has two new transfer functions: x80tod and dtox80.  They can 
  759.             be used to directly transform 68k 80-bit extended data types to double
  760.             and back for PowerPC based machines without using the functions
  761.             x80told or ldtox80.  Double rounding may occur. 
  762.         */
  763. EXTERN_API_C( double ) x80tod(const extended80 *x80);
  764.  
  765. EXTERN_API_C( void ) dtox80(const double *x, extended80 *x80);
  766.  
  767. #endif  /* !defined(__NOEXTENSIONS__) */
  768.  
  769. #endif  /* TARGET_CPU_PPC */
  770.  
  771. #if TARGET_CPU_X86
  772. #ifndef __NOEXTENSIONS__
  773. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  774.  
  775. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  776.  
  777. #endif  /* !defined(__NOEXTENSIONS__) */
  778.  
  779. #endif  /* TARGET_CPU_X86 */
  780.  
  781. #else
  782. /*
  783.     Non-Mac platforms may have long doubles.
  784. */
  785. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  786.  
  787. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  788.  
  789. #endif  /* TARGET_OS_MAC */
  790.  
  791.  
  792. #if PRAGMA_STRUCT_ALIGN
  793.     #pragma options align=reset
  794. #elif PRAGMA_STRUCT_PACKPUSH
  795.     #pragma pack(pop)
  796. #elif PRAGMA_STRUCT_PACK
  797.     #pragma pack()
  798. #endif
  799.  
  800. #ifdef PRAGMA_IMPORT_OFF
  801. #pragma import off
  802. #elif PRAGMA_IMPORT
  803. #pragma import reset
  804. #endif
  805.  
  806. #ifdef __cplusplus
  807. }
  808. #endif
  809.  
  810. #endif /* __FP__ */
  811.  
  812.